package GUI;

import redis.clients.jedis.Jedis;
import swimming.Redis;
import use.manageruse;
import swimming.manager;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.List;


public class denglu {
    private JPanel panel1;
    private JButton 欢迎进入Button;
    private JTextField textField1;
    private JPasswordField passwordField1;
    private static String pass;
    public static void iface()
    {
        JFrame frame = new JFrame("游泳馆会员管理系统");
        frame.setSize(500,400);
        frame.setLocation(400,200);

        denglu t1=new denglu();
        frame.add(t1.panel1);

        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    public denglu()
    {

        欢迎进入Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Redis j=new Redis();
                Jedis work=j.Redis();
                if (textField1.getText().equals("")) {
                    JOptionPane.showMessageDialog(null, "用户名不能为空！", "提示",
                            JOptionPane.INFORMATION_MESSAGE);
                }
                else if (passwordField1.getText().equals("")) {
                    JOptionPane.showMessageDialog(null, "密码不能为空！", "提示",
                            JOptionPane.INFORMATION_MESSAGE);
                }
                else{
                        if(!work.exists(textField1.getText()))
                        {
                            JOptionPane.showMessageDialog(null, "管理人不存在", "提示",
                                    JOptionPane.INFORMATION_MESSAGE);
                            work.close();
                        }
                        else if(!work.get(textField1.getText()).equals(passwordField1.getText()))
                        {
                            JOptionPane.showMessageDialog(null, "密码错误", "提示",
                                    JOptionPane.INFORMATION_MESSAGE);
                            work.close();
                        }
                        else
                        {
                            pass=textField1.getText();
                            work.close();
                            new usecard().iface();
                        }
                }
            }
        });
    }
    public String getpass()
    {
        return pass;
    }
    public static void main(String[] args) {
        iface();
    }
}
